package com.lin.androidgame21;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;

import java.io.IOException;

/***

 *Create By LWL Write

 **/

public class MySoundPool {

    private Context context;
    private SoundPool soundPool;
    private final int sound_enemy_die;
    private final int sound_enemy_gong;
    private final int sound_fire;
    private final int sound_ice;
    private final int sound_lixiaoyaoshang;
    private final int sound_zhanglingershang;

    public MySoundPool(Context context){
        this.context=context;
        if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP){
            soundPool=new SoundPool.Builder().setMaxStreams(5).build();
        }else {
            soundPool=new SoundPool(5, AudioManager.STREAM_MUSIC,0);
        }
        sound_enemy_die=getSound("enemy_die.wav");
        sound_enemy_gong=getSound("enemy_gong.wav");
        sound_fire=getSound("fire.ogg");
        sound_ice=getSound("ice.wav");
        sound_lixiaoyaoshang=getSound("lixiaoyaoshang.wav");
        sound_zhanglingershang=getSound("zhanglingershang.wav");
    }

    private int getSound(String filename) {
        int soundID=0;
        try{
            soundID=soundPool.load(context.getAssets().openFd(filename),1);
        }catch (IOException e){
            e.printStackTrace();
        }
        return soundID;
    }

    public void play(int soundID){
        soundPool.play(soundID,1,1,1,0,1);
    }

    public int getSound_enemy_die(){
        return sound_enemy_die;
    }

    public int getSound_enemy_gong(){
        return sound_enemy_gong;
    }

    public int getSound_fire(){
        return sound_fire;
    }

    public int getSound_ice(){
        return sound_ice;
    }

    public int getSound_lixiaoyaoshang(){
        return sound_lixiaoyaoshang;
    }

    public int getSound_zhanglingershang(){
        return sound_zhanglingershang;
    }
}
